cmake_minimum_required(VERSION 3.10)
project(McsImporter)

set(CMAKE_CXX_STANDARD 17)
SET(PROJECT_ROOT_PATH "${PROJECT_SOURCE_DIR}")
SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_BINARY_DIR}/bin/")
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin/")
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib/")
link_directories("${PROJECT_BINARY_DIR}/bin/;${PROJECT_BINARY_DIR}/lib/")

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_PREFIX_PATH "C:/Qt/5.13.1/mingw73_64")
find_package(Qt5 COMPONENTS Widgets Core REQUIRED)

if(WIN32)
    set(CMAKE_PREFIX_PATH "${PROJECT_ROOT_PATH}/opencv")
    find_package(OpenCV 4 REQUIRED)
    file(GLOB OPENCV_SHARED_LIB "${PROJECT_ROOT_PATH}/opencv/x64/mingw/bin/*.dll")
    file(COPY ${OPENCV_SHARED_LIB} DESTINATION ${EXECUTABLE_OUTPUT_PATH})
else()
    find_package(OpenCV 4 REQUIRED)
endif()

include_directories(ui)
add_subdirectory(ui)
aux_source_directory(ui UI_SRC)

include_directories(ui/widget)
add_subdirectory(ui/widget)
aux_source_directory(ui/widget WIDGET_SRC)

include_directories(util)
add_subdirectory(util)
aux_source_directory(util UTIL_SRC)

include_directories(mcs)
add_subdirectory(mcs)
aux_source_directory(mcs MCS_SRC)


#set(QRC_SOURCE_FILES resource/resource.qrc)
qt5_add_resources(RESOURCE_FILES ${QRC_SOURCE_FILES})

add_executable(McsImporter main.cpp ${UI_SRC} ${WIDGET_SRC} ${MCS_SRC} ${UTIL_SRC} ${RESOURCE_FILES})

if(WIN32)
    if(MSVC)
        set_target_properties(McsImporter PROPERTIES WIN32_EXECUTABLE YES LINK_FLAGS "/ENTRY:mainCRTStartup")
    elseif(CMAKE_COMPILER_IS_GNUCXX)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows")
    else()
        message(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)")
    endif(MSVC)
elseif(APPLE)
    set_target_properties(McsImporter PROPERTIES MACOSX_BUNDLE YES)
elseif(UNIX)
    # Nothing special required
else()
    message(SEND_ERROR "You are on an unsupported platform! (Not Win32, Mac OS X or Unix)")
endif(WIN32)

target_link_libraries(McsImporter PUBLIC ${OpenCV_LIBS} PRIVATE Qt5::Widgets Qt5::Core)
